<template>
    <div>
        <i :class="switchLangClass" @click="switchLang"></i>
    </div>
</template>

<script>
export default {
    name:'SwitchLang',
    data(){
        return{
            langClassZh: 'switch-lang iconfont icon-lang-zh',
            langClassEn: 'switch-lang iconfont icon-lang-en',
            switchLangClass: ''
        }
    },
    computed: {},
    components: {},
    methods: {
        switchLang(){//切换语言
            if(this.$i18n.locale==='zh-CN'){
                this.$i18n.locale='en';
                // this.$i18n.switchLang('en');
                this.switchLangClass = this.langClassEn;
            }else {
                this.$i18n.locale='zh-CN';
                // this.$i18n.switchLang('zh-CN');
                this.switchLangClass = this.langClassZh;
            }
            sessionStorage.setItem('chhuangboot.lang', this.$i18n.locale);
            this.$emit('switchLang', this.$i18n.locale);
        }
    },
    mounted() {
        //初始化语言
        if(this.$i18n.locale==='zh-CN'){//语言是中文
            this.switchLangClass = this.langClassZh;
        }else {//其它语言都是英文
            this.switchLangClass = this.langClassEn;
        }
    }
}

</script>
<style scoped>
.switch-lang{
  font-size: 30px !important; 
  color: #409EFF; 
  cursor: pointer;
}
</style>